<template>
  <d2-container>
    <el-form :model="FormSearch" status-icon label-width="100px" class="demo-ruleForm">
      <el-row :gutter="24">
        <el-col :span="7">
          <el-form-item label="条件查找" prop="goodName">
            <el-input type="text" v-model="FormSearch.goodName" placeholder="请输入商品名称"></el-input>
          </el-form-item>
        </el-col>
        <el-col :span="5">
          <el-button type="primary" @click="searchClick()">查询</el-button>
          <el-button @click="resetForm()">重置</el-button>
        </el-col>
        <el-col :span="8">
          <!-- <el-upload
            class="upload-demo"
            action="https://jsonplaceholder.typicode.com/posts/"
            :on-success="handleChange"
            :show-file-list="false"
          >
            <el-button type="primary">导入库存</el-button>
          </el-upload> -->
        </el-col>
      </el-row>
    </el-form>
    <!-- 数据表格 -->
    <d2-crud
      ref="d2Crud"
      :columns="columns"
      :data="data"
      :pagination="page"
      @pagination-current-change="paginationCurrentChange"
    >
    </d2-crud>
  </d2-container>
</template>

<script>
import { stockList } from "@/api/goods/index";

export default {
  data() {
    return {
      // 搜索数据
      FormSearch: {
        goodName: ""
      },
      // 字段名称
      columns: [
        {
          title: "商品名称",
          key: "name",
          align: "center"
        },
        {
          title: "进价",
          key: "name",
          align: "center"
        },
        {
          title: "售价",
          key: "name",
          align: "center"
        },
        {
          title: "库存数量",
          key: "name",
          align: "center"
        },
        {
          title: "规格",
          key: "name",
          align: "center"
        },
      ],
      // 列表数据
      data: [],
      // 分页数据
      page: {
        total: 0,
        pageIndex: 1,
        pageSize: 10
      }
    };
  },
  created() {
    let params = {
      page: this.page.pageIndex,
      limit: this.page.pageSize
    };
    this.init(params);
  },
  methods: {
    // 初始化身体数据列表
    init(params) {
      this.data = [
        {
          name: "二级价格",
          id: 0
        },
        {
          name: "王小虎",
          id: 3
        },
        {
          name: "王小虎",
          id: 4
        },
        {
          name: "王小虎",
          id: 5
        }
      ];
      this.page.total = 20;
      /* stockList(params)
        .then(res => {
          console.log(res);
          if (res.success) {
            this.data = res.rows;
            this.page.total = res.total;
          }
        })
        .catch(err => {
          this.$message.error(err);
        }); */
    },

    // 分页数改变，调用
    paginationCurrentChange(pageIndex) {
      let params = {
        limit: this.page.pageSize,
        goodName: this.FormSearch.goodName
      };
      params.page = this.page.pageIndex = pageIndex;
      this.init(params);
    },

    // 上传文件成功或失败的回调
    handleChange(response, file, fileList) {
      console.log(response, file, fileList);
    },

    // 条件查询搜索
    searchClick() {
      let params = {
        page: 1,
        limit: 10
      };
      params.fname = this.FormSearch.goodName;
      this.init(params);
    },

    // 重置查询
    resetForm() {
      this.FormSearch.goodName = "";
      let params = {
        page: 1,
        limit: 10
      };
      this.init(params);
    },
  }
};
</script>
<style lang="scss" scoped>
</style>
